package com.cz.mes;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.cz.token.LoginService;

import java.util.HashMap;
import java.util.Map;

public class PmsUpdate {
    public static void main(String[] args) {
        LoginService loginService = new LoginService();
        String loginToken = loginService.getProdToken();

        Map<String, Object> params = new HashMap<>();
        params.put("type",1);
        params.put("productCodeList",new String[]{"SFM-60-M16-150-C"});
        queryPms(params,loginToken);

    }

    public static void queryPms(Map<String, Object> pmsMap, String loginToken) {
        String url = "http://gateway.prod.ant2world.com/at-pms-api/productBaseInfo/getBaseInfo";
        HttpRequest request = HttpUtil.createPost(url);


        String token = "Bearer "+loginToken;

        request.header("Authorization", token);
        String data = JSONUtil.toJsonStr(pmsMap);
        System.out.println("请求参数:" + data);
        request.body(data, "application/json");
        HttpResponse response = request.execute();
        if (response.isOk()) {
            System.out.println(response.body());
        } else {
            System.out.println("error:" + response.getStatus());
        }
    }
}
